package com.ficus.road.maintain.config;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author shiye
 * @create 2020-06-12 17:18
 */
@Configuration
@ConfigurationProperties(prefix = "oss")
public class AliyunOssConfig {

    //文件最大上传大小
    public static long FILE_MAX_SIZE = 1024 * 1024 * 10l;
    //图片过期时间 1年
    public static long FILE_EXPIRATION_TIME = 1000 * 3600 * 24 * 365;
    /**
     * 阿里云 oss 站点
     */
    private String endpoint;
    /**
     * 阿里云 oss 公钥
     */
    private String accessKeyId;
    /**
     * 阿里云 oss 私钥
     */
    private String accessKeySecret;
    /**
     * 阿里云 oss 文件根目录
     */
    private String bucketName;

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    @Bean
//    @Scope("prototype")
    public OSSClient ossClient() {
        return new OSSClient(endpoint,
                new DefaultCredentialProvider(accessKeyId, accessKeySecret),
                new ClientConfiguration());
    }
}